#include "ResponseEditor.h"

namespace Xps
{
	ResponseEditor::ResponseEditor(XpsAssets::Response* resp, QWidget *parent)
	{
		setObjectName("ResponseEditor");
		QGroupBox* gb;
		QVBoxLayout* content_layout = new QVBoxLayout();
		QGridLayout* attributes_layout = new QGridLayout();

		setLayout(content_layout);
		
		text = new QLineEdit();
				
		content_layout->addWidget(new QLabel("Response:"));
		content_layout->addWidget(text);
		
		if (resp != NULL &&  resp->attributes()->count() > 0)
		{
			gb = new QGroupBox("Attributes");
			gb->setStyleSheet("QGroupBox { border: 1px solid gray; border-radius: 5px; margin-top: 8px; } "
								"QGroupBox::title { subcontrol-origin: margin; left: 10px; padding: 0 5px; } ");
			content_layout->addWidget(gb);
			for(int i = 0; i < resp->attributes()->count(); i++)
			{
				editor_lbl.append(new QLabel("test"));
				ra_editor.append(new ResponseAttributeEditor()); 
				attributes_layout->addWidget(editor_lbl.last(),i,0);
				attributes_layout->addWidget(ra_editor.last(),i,1);
			}
			gb->setLayout(attributes_layout);
		}
		content_layout->insertStretch(3,100);
			
	}

	void ResponseEditor::write(XpsAssets::AssetData* ad)
	{
		XpsAssets::Response* r = (XpsAssets::Response*) ad;

		r->setText(text->text());
	}

	void ResponseEditor::read(XpsAssets::AssetData* ad)
	{
		XpsAssets::Response* r = (XpsAssets::Response*) ad;

		text->setText(r->text());
	}
}